package com.itheima.tanhua.dubbo.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.itheima.tanhua.autoconfig.template.AipFaceTemplate;
import com.itheima.tanhua.autoconfig.template.OssTemplate;
import com.itheima.tanhua.dubbo.mappers.UserMapper;
import com.itheima.tanhua.dubbo.service.UserService;
import com.itheima.tanhua.model.domain.User;
import com.itheima.tanhua.model.domain.UserInfo;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.InputStream;
import java.util.Date;

/**
 * @author H Monster
 */
@DubboService
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private OssTemplate ossTemplate;

    @Autowired
    private AipFaceTemplate aipFaceTemplate;

    @Override
    public User getUserByPhone(String phone) {
        if (StringUtils.isEmpty(phone)) {
            return null;
        }
        return userMapper.getUserByPhone(phone);
    }

    @Override
    public User createUserByPhone(String phone) {
        if (StringUtils.isEmpty(phone)) {
            return null;
        }

        User user = new User();
        user.setMobile(phone);
        user.setPassword(SecureUtil.md5(phone));
        user.setCreated(new Date());
        user.setUpdated(new Date());

        int result = userMapper.insertUser(user);

        return result == 1 ? user : null;
    }

    @Override
    public UserInfo getUserInfoById(String userId) {

        return userMapper.getUserInfoById(userId);
    }

    @Override
    public void createUserInfo(UserInfo userInfo) {

        userMapper.createUserInfo(userInfo);

    }

    @Override
    public void updateHead(UserInfo userInfo) {
        userMapper.updateHead(userInfo);
    }


}


